package com.test.cordova.provider.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 用户数据库
 */

public class UserDBHelper extends SQLiteOpenHelper {

    public UserDBHelper(Context context) {
        super(context,DBConstants.DB_NAME,null, DBConstants.DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建两个表格:用户表 和职业表
        db.execSQL("CREATE TABLE IF NOT EXISTS " + DBConstants.USER_TABLE +"("+DBConstants.USER_COLUM_ID+" INTEGER PRIMARY KEY AUTOINCREMENT," + DBConstants.USER_COLUM_NAME+" TEXT)");
        db.execSQL("CREATE TABLE IF NOT EXISTS " + DBConstants.JOB_TABLE +"("+DBConstants.JOB_COLUM_ID+" INTEGER PRIMARY KEY AUTOINCREMENT," + DBConstants.JOB_COLUM_NAME+" TEXT)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (newVersion > oldVersion) {
            db.execSQL("DROP TABLE IF EXISTS "+DBConstants.USER_TABLE+";");
            db.execSQL("DROP TABLE IF EXISTS "+DBConstants.JOB_TABLE+";");
            onCreate(db);
        }
    }
}
